package com.funo.logic.generate.wrapper;

import java.util.LinkedHashSet;
import java.util.Set;

public class GenericsClassWrapper extends ClassWrapper {
    /**
     * 泛型引用列表
     */
    private Set<ClassWrapper> genericsList = new LinkedHashSet<>();

    public static GenericsClassWrapper of(String name) {
        GenericsClassWrapper genericsClassWrapper = new GenericsClassWrapper();
        genericsClassWrapper.setFullName(name);
        genericsClassWrapper.setName(getClassShortRawName(name));
        genericsClassWrapper.setShortName(getClassShortName(name));
        genericsClassWrapper.setShortRawName(getClassShortRawName(name));
        genericsClassWrapper.setPackageName(getClassPackage(name));
        genericsClassWrapper.setParameterizedType(getClassParameterizedType(name));
        return genericsClassWrapper;
    }

    public static GenericsClassWrapper of(Class clazz) {
        return of(clazz.getName());
    }

    public static GenericsClassWrapper of(String name, String packageName) {
        GenericsClassWrapper genericsClassWrapper = new GenericsClassWrapper();
        genericsClassWrapper.setFullName(name);
        genericsClassWrapper.setName(getClassShortRawName(name));
        genericsClassWrapper.setShortName(getClassShortName(name));
        genericsClassWrapper.setShortRawName(getClassShortRawName(name));
        genericsClassWrapper.setPackageName(packageName);
        genericsClassWrapper.setParameterizedType(getClassParameterizedType(name));
        return genericsClassWrapper;
    }

    public void addGenerics(ClassWrapper generics) {
        if (genericsList.stream().noneMatch(classWrapper -> classWrapper.getFullName().equals(generics.getFullName()))) {
            genericsList.add(generics);
        }
    }

    public Set<ClassWrapper> getGenericsList() {
        return genericsList;
    }
}
